﻿namespace S7.Net.Types
{
    using System;

    public static class DWord
    {
        public static uint FromByteArray(byte[] bytes)
        {
            return (uint) ((((bytes[0] << 0x18) | (bytes[1] << 0x10)) | (bytes[2] << 8)) | bytes[3]);
        }

        public static uint FromBytes(byte b1, byte b2, byte b3, byte b4)
        {
            return (uint) ((((b4 << 0x18) | (b3 << 0x10)) | (b2 << 8)) | b1);
        }

        public static uint[] ToArray(byte[] bytes)
        {
            uint[] numArray = new uint[bytes.Length / 4];
            int num = 0;
            for (int i = 0; i < (bytes.Length / 4); i++)
            {
                byte[] buffer1 = new byte[] { bytes[num++], bytes[num++], bytes[num++], bytes[num++] };
                numArray[i] = FromByteArray(buffer1);
            }
            return numArray;
        }

        public static byte[] ToByteArray(uint[] value)
        {
            ByteArray array = new ByteArray();
            foreach (uint num2 in value)
            {
                array.Add(ToByteArray(num2));
            }
            return array.array;
        }

        public static byte[] ToByteArray(uint value)
        {
            return new byte[] { ((byte) ((value >> 0x18) & 0xff)), ((byte) ((value >> 0x10) & 0xff)), ((byte) ((value >> 8) & 0xff)), ((byte) (value & 0xff)) };
        }
    }
}

